<template>
  <div id="userLoginPage">
    <a-form
      :model="form"
      style="max-width: 480px; margin: 0 auto"
      label-align="left"
      auto-label-width
      @submit="handleSubmit"
    >
      <a-form-item field="userAccount" label="用户账号">
        <a-input v-model="form.userAccount" placeholder="请输入账号" />
      </a-form-item>
      <a-form-item field="userPassword" label="用户密码">
        <a-input-password v-model="form.userPassword" placeholder="请输入密码" />
      </a-form-item>
      <a-form-item>
        <a-button html-type="submit" type="primary">登陆</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue'
import { UserControllerService } from '../../../openapi'
import { useRouter } from 'vue-router'
import message from '@arco-design/web-vue/es/message'
import {useLoginUserStore} from "@/stores/loginUserStore.ts";
import {json} from "node:stream/consumers";

const router = useRouter()
const loginUserStore = useLoginUserStore();

/**
 * 表单信息
 */
const form = reactive({
  userAccount: '',
  userPassword: '',
})

//提交表单
const handleSubmit = async () => {
  const res = await UserControllerService.loginUsingPost(form)
  if (res.code === 200 && res.data) {
    loginUserStore.setLoginUser(res.data)
    await router.push({
      path: '/',
      replace: true,
    })
  } else {
    message.error(res.message)
  }
}
</script>

<style scoped>
#userLoginPage {
  margin-top: 100px;
}
</style>
